<?php

class Ynadvsearch_Installer extends Engine_Package_Installer_Module {
	function onInstall() {
		//
		// install content areas
		//
		$db     = $this->getDb();
   		$select = new Zend_Db_Select($db);

      	// BROWSE STORE
	     $select = new Zend_Db_Select($db);
	     $select
	      ->from('engine4_core_pages')
	      ->where('name = ?', 'ynadvsearch_search_index')
	      ->limit(1);
	      ;
	    $info = $select->query()->fetch();
	
	    if( empty($info) ) {
	      $db->insert('engine4_core_pages', array(
	        'name' => 'ynadvsearch_search_index',
	        'displayname' => 'YouNet Advanced Search Page',
	        'title' => 'YouNet Advanced Search Page',
	        'description' => 'YouNet Advanced Search Page',
	      ));
	      $page_id = $db->lastInsertId('engine4_core_pages');
	
	      // containers
	       $db->insert('engine4_core_content', array(
	        'page_id' => $page_id,
	        'type' => 'container',
	        'name' => 'top',
	        'parent_content_id' => null,
	        'order' => 1,
	        'params' => '',
	      ));
	      $top_id = $db->lastInsertId('engine4_core_content');
	       $db->insert('engine4_core_content', array(
	        'page_id' => $page_id,
	        'type' => 'container',
	        'name' => 'middle',
	        'parent_content_id' => $top_id,
	        'order' => 6,
	        'params' => '',
	      ));
	       $middle_id = $db->lastInsertId('engine4_core_content');  
	       $db->insert('engine4_core_content', array(
	        'page_id' => $page_id,
	        'type' => 'widget',
	        'name' => 'ynadvsearch.search-field',
	        'parent_content_id' => $middle_id,
	        'order' => 3,
	        'params' => '',
	      ));
	      $db->insert('engine4_core_content', array(
	        'page_id' => $page_id,
	        'type' => 'container',
	        'name' => 'main',
	        'parent_content_id' => null,
	        'order' => 2,
	        'params' => '',
	      ));
	      $container_id = $db->lastInsertId('engine4_core_content');
	
	      $db->insert('engine4_core_content', array(
	        'page_id' => $page_id,
	        'type' => 'container',
	        'name' => 'middle',
	        'parent_content_id' => $container_id,
	        'order' => 6,
	        'params' => '',
	      ));
	      $middle_id = $db->lastInsertId('engine4_core_content');
	      
	      $db->insert('engine4_core_content', array(
	        'page_id' => $page_id,
	        'type' => 'container',
	        'name' => 'left',
	        'parent_content_id' => $container_id,
	        'order' => 5,
	        'params' => '',
	      ));
	      $left_id = $db->lastInsertId('engine4_core_content');
	      // middle column
	      $db->insert('engine4_core_content', array(
	        'page_id' => $page_id,
	        'type' => 'widget',
	        'name' => 'ynadvsearch.search-results',
	        'parent_content_id' => $middle_id,
	        'order' => 6,
	        'params' => '',
	      ));
     
	      // right column
	      
	      $db->insert('engine4_core_content', array(
	        'page_id' => $page_id,
	        'type' => 'widget',
	        'name' => 'ynadvsearch.modules-list',
	        'parent_content_id' => $left_id,
	        'order' => 17,
	        'params' => '',
	      ));
	      
	    }
		parent::onInstall();
	}

}